package businesslogic.userBl;

import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.util.ArrayList;

import po.userPO.StudentPO;
import po.userPO.UserPO;
import vo.userVO.StudentVO;
import businesslogicservice.userblservice.TeacherBLService;
import dataservice.userDataService.UserDatabaseService;

public class Teacher extends User implements TeacherBLService{

	private static final String ADDRESS_STRING="localhost";
	
	public Teacher(String UserID) {
		super(UserID);
		// TODO Auto-generated constructor stub
	}

	

	@Override
	public ArrayList<StudentVO> getStudentList(String departmentID)throws Exception {
		ArrayList<StudentVO> studentList=new ArrayList<StudentVO>();
		if(System.getSecurityManager()==null)
            System.setSecurityManager(new RMISecurityManager());
		try{
			
			UserDatabaseService userDataService = (UserDatabaseService)Naming.lookup("rmi://"+ADDRESS_STRING+":8888/userData");
		
			
			ArrayList<UserPO> findResult=userDataService.findAllByDepartment(0,departmentID);
			
			for(UserPO user:findResult){
				StudentPO userpo=(StudentPO)user;
				StudentVO student=new StudentVO(userpo.getId(),userpo.getName(),userpo.getDepartmentId(),userpo.getGrade());
				studentList.add(student);
				
			}
			
			return studentList;
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
	}

	
	

	
}
